Skip to content

fix: Clear stale GH_HOST and remove false fork PR detection (#24208)#24221

Merged
lpcox merged 4 commits intomainfrom
fix/gh-host-and-fork-detection
Apr 3, 2026
Merged

fix: Clear stale GH_HOST and remove false fork PR detection (#24208)#24221
lpcox merged 4 commits intomainfrom
fix/gh-host-and-fork-detection

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Apr 3, 2026

Summary

Fixes the PR checkout failure reported in #24208 by addressing two interacting bugs.

Changes

1. Clear stale GH_HOST on github.com (configure_gh_for_ghe.sh)

The script returned early for github.com without touching GH_HOST. If a stale value was present (e.g., localhost:18443 from a prior DIFC proxy), it persisted and caused gh pr checkout to fail with:

none of the git remotes configured for this repository correspond to the GH_HOST environment variable

Fix: Explicitly unset GH_HOST when it has a stale non-github.com value, and write GH_HOST=github.com to GITHUB_ENV for downstream steps.

2. Remove false fork PR detection (pr_helpers.cjs)

detectForkPR() checked head.repo.fork === true to detect fork PRs. But this flag indicates whether the repository itself is a fork of another repo — not whether the PR is cross-repo. For same-repo PRs in forked repositories (common in OSS like fsprojects/FSharp.Control.AsyncSeq), this produced a false positive that forced the gh pr checkout path (sensitive to GH_HOST) instead of the fast git fetch path (not sensitive).

Fix: Removed the head.repo.fork check. Fork PR detection now relies solely on comparing head.repo.full_name vs base.repo.full_name, which correctly identifies cross-repo PRs.

Why both bugs were needed

  • Bug 1 left a stale GH_HOST that breaks gh pr checkout
  • Bug 2 forced the use of gh pr checkout (which depends on GH_HOST) instead of git fetch (which doesn't)

Fixing either independently prevents the failure.

Testing

  • Updated pr_helpers.test.cjs — all 24 tests pass
  • Existing tests: should NOT treat same-repo PR as fork even when repo has fork flag validates the core fix
  • New test: should detect cross-repo fork PR by different full_name ensures real fork PRs still detected

Fixes #24208
Closes #24217
Closes #24218

Two bugs interacted to cause PR checkout failures on github.com repos:

1. configure_gh_for_ghe.sh: For github.com, the script returned early
   without clearing GH_HOST. A stale value (e.g., localhost:18443 from
   a prior DIFC proxy run) persisted, causing 'gh pr checkout' to fail
   with 'none of the git remotes correspond to GH_HOST'. Now explicitly
   unsets stale GH_HOST values on the github.com path.

2. pr_helpers.cjs: detectForkPR() checked head.repo.fork to detect fork
   PRs, but this flag indicates whether the *repository itself* is a fork
   (common in OSS), not whether the PR is cross-repo. This caused false
   positives that forced the slow 'gh pr checkout' path (which depends on
   GH_HOST) instead of fast 'git fetch' (which doesn't). Removed the
   fork flag check; now only uses full_name comparison.

Fixes #24208
Closes #24217
Closes #24218

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 3, 2026 03:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes PR checkout failures caused by stale GH_HOST values and incorrect “fork PR” detection logic that could force the gh pr checkout path.

Changes:

  • Update configure_gh_for_ghe.sh to clear stale GH_HOST when running against github.com, and persist GH_HOST=github.com via GITHUB_ENV.
  • Simplify detectForkPR() to rely on head.repo presence and head.repo.full_name vs base.repo.full_name, removing the incorrect head.repo.fork signal.
  • Adjust/add unit tests in pr_helpers.test.cjs to validate the updated fork detection behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
actions/setup/sh/configure_gh_for_ghe.sh Clears stale GH_HOST when targeting github.com to prevent gh host/remote mismatch errors.
actions/setup/js/pr_helpers.cjs Removes incorrect fork-flag logic; fork PR detection now uses cross-repo full_name comparison.
actions/setup/js/pr_helpers.test.cjs Updates tests to reflect the new fork PR detection semantics and adds a cross-repo case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +15
* NOTE: We intentionally do NOT check head.repo.fork. That flag indicates
* whether the repository *itself* is a fork of another repo, not whether
* the PR is cross-repo. A same-repo PR in a forked repository (common in
* OSS) would have fork=true but is NOT a cross-repo fork PR. Using that
* flag caused false positives that forced `gh pr checkout` instead of fast
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detectForkPR() no longer uses head.repo.fork and will never return the reason "head.repo.fork flag is true", but actions/setup/js/checkout_pr_branch.test.cjs currently mocks ./pr_helpers.cjs with the old fork-flag-based logic and asserts against that reason. This makes the checkout tests inconsistent with the production implementation and reduces coverage for the bug this PR is fixing. Update those tests to use the real detectForkPR (preferred) or at least mirror the new full_name-comparison logic and expected reasons.

Copilot uses AI. Check for mistakes.
lpcox and others added 3 commits April 2, 2026 20:37
The test 'should detect fork PR via fork flag and fail early' assumed
that head.repo.fork=true with same full_name meant a cross-repo fork PR.
After fixing detectForkPR() to only use full_name comparison (#24208),
same-repo PRs in forked repositories are correctly treated as non-fork,
allowing push to proceed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The mock detectForkPR() in checkout_pr_branch.test.cjs replicated the
old fork-flag-based logic, making tests inconsistent with production.
Updated the mock to match the corrected full_name-only comparison and
updated assertions to verify that same-repo PRs in forked repositories
use the fast git fetch path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests asserted 'integrity check failed' but the error message was
changed to 'is outdated or unverifiable' in #24198. Updated all 6
assertions to match the current production error format.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit 790e8ca into main Apr 3, 2026
56 checks passed
@lpcox lpcox deleted the fix/gh-host-and-fork-detection branch April 3, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants